package com.bfsuol.yihang.cars.domain;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bfsuol.yihang.cars.dao.VehicleMapper;
import com.bfsuol.yihang.cars.dto.VehicleDTO;
import com.bfsuol.yihang.cars.entity.VehicleEntity;
import com.bfsuol.yihang.customers.dao.CustomerMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class VehicleServiceImpl extends ServiceImpl<VehicleMapper, VehicleEntity> implements VehicleService {

    @Autowired
    private VehicleMapper vehicleMapper;

    @Autowired
    public VehicleMapper getBaseMapper(){
        return vehicleMapper;
    }

    @Override
    public VehicleDTO getOneByVehicleNo(String vehicleNo) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("vehicle_no", vehicleNo);
        VehicleEntity vehicleEntity = this.getOne(queryWrapper);
        if(vehicleEntity==null){
            return null;
        }
        VehicleDTO vehicleDTO = new VehicleDTO();
        BeanUtils.copyProperties(vehicleEntity,vehicleDTO);
        return vehicleDTO;
    }
}
